/**
 * 员工积分管理初始化
 */
var EmpPoints = {
    id: "EmpPointsTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    queryData : {},
    layerIndex: -1,
    width: '800px',
    height: '420px'
};

/**
 * 初始化表格的列
 */
EmpPoints.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '年度', field: 'year', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '员工编码', field: 'empCode', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '员工姓名', field: 'empName', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '二级系统ERP编号', field: 'erpCode', visible: false, align: 'center', valign: 'middle', sortable: true},
            {title: '   部门(单位）  ', field: 'deptName', visible: true, align: 'center', valign: 'middle', sortable: true},
            {title: '   处/室    ', field: 'placeName', visible: true, align: 'center', valign: 'middle', sortable: true},
            {title: '   班组   ', field: 'teamName', visible: true, align: 'center', valign: 'middle', sortable: true},
            {title: '   岗位类别   ', field: 'postType', visible: true, align: 'center', valign: 'middle', sortable: true},
            {title: ' 职务（岗位） ', field: 'post', visible: true, align: 'center', valign: 'middle', sortable: true},
            {title: '用工类型', field: 'laborType', visible: true, align: 'center', valign: 'middle', sortable: true},

            {title: '网络培训', field: 'networkTrainPoints', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '脱产培训', field: 'fulltimeTrainPoints', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '学历提升', field: 'degreeTrainPoints', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '专业技术资格', field: 'protechTrainPoints', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '职业资格', field: 'proqualifyTrainPoints', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '执业资格', field: 'practicePoints', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '专家人才', field: 'expertTalentsPoints', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '竞赛调考', field: 'contestPoints', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '师徒带', field: 'mentoringRelationPoints', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '认证培训师', field: 'trainerAuthenPoints', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '优秀培训师', field: 'trainerExcellentPoints', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '项目培训师', field: 'projectAuthenPoints', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '周期培训师', field: 'cycleAuthenPoints', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '培训项目', field: 'trainProgramPoints', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '总积分', field: 'totalPoint', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '星级', field: 'start', visible: true, align: 'center', valign: 'middle',sortable: true}
    ];
};

/**
 * 检查是否选中
 */
EmpPoints.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        var i = selected.length - 1;
        EmpPoints.seItem = selected[i];
        return true;
    }
};

/**
 * 点击导出培训档案
 */
EmpPoints.exportEmp = function () {
    debugger
    if (this.check()) {

        window.open(Feng.ctxPath + "analysis/exportTrainFile?empCode="+this.seItem.empCode+"&year="+this.seItem.year,"_parent");

        // var ajax = new $ax(Feng.ctxPath + "/analysis/exportTrainFile", function (data) {
        //     Feng.success("导出成功!");
        //     if(data.data){
        //
        //     }
        // }, function (data) {
        //     Feng.error("导出失败!" + data.responseJSON.message + "!");
        // });
        // ajax.set("empCode",this.seItem.empCode);
        // ajax.set("year",this.seItem.year);
        // ajax.set("totalPoint",this.seItem.totalPoint);
        // ajax.start();
    }else{
        Feng.info("请先选中表格中的某一记录！");
    }
};

/**
 * 导出积分
 */
EmpPoints.export = function () {
    // if (this.check()) {
    // var ajax = new $ax(Feng.ctxPath + "/empPoints/exportTrainPoint", function (data) {
    //     Feng.success("导出成功!");
    //     if(data.data){
    //         debugger
    //
    //     }
    // }, function (data) {
    //     Feng.error("导出失败!" + data.responseJSON.message + "!");
    // });
    // debugger
    // ajax.set(EmpPoints.queryData);
    // ajax.start();
    // }
    EmpPoints.queryData.department =  EmpPoints.queryData.department== undefined ? "" : EmpPoints.queryData.department;
    EmpPoints.queryData.team =  EmpPoints.queryData.team== undefined ? "" : EmpPoints.queryData.team;
    EmpPoints.queryData.min =  EmpPoints.queryData.min== undefined ? "" : EmpPoints.queryData.min;
    EmpPoints.queryData.year =  EmpPoints.queryData.year== undefined ? "" : EmpPoints.queryData.year;
    EmpPoints.queryData.place =  EmpPoints.queryData.place== undefined ? "" : EmpPoints.queryData.place;
    EmpPoints.queryData.postType =  EmpPoints.queryData.postType== undefined ? "" : EmpPoints.queryData.postType;
    EmpPoints.queryData.max =  EmpPoints.queryData.max== undefined ? "" : EmpPoints.queryData.max;
    debugger
    window.open(Feng.ctxPath + "empPoints/exportTrainPoint?" +
        "&department="+EmpPoints.queryData.department+
        "&team="+EmpPoints.queryData.team+
        "&min="+EmpPoints.queryData.min+
        "&year="+EmpPoints.queryData.year+
        "&place="+EmpPoints.queryData.place+
        "&postType="+EmpPoints.queryData.postType+
        "&max="+EmpPoints.queryData.max
        ,"_parent");
};



/**
 * 打开查看员工积分详情
 */
EmpPoints.openEmpPointsDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '员工积分详情',
            area: [EmpPoints.width, EmpPoints.height], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/empPoints/empPoints_update/' + EmpPoints.seItem.id
        });
        this.layerIndex = index;
    };
};

/**
 * 删除员工积分
 */
EmpPoints.delete = function () {
    debugger
    if (this.check()) {
        var operation = function() {
            var ajax = new $ax(Feng.ctxPath + "/empPoints/delete", function (data) {
                Feng.success("删除成功!");
                EmpPoints.table.refresh();
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("empPointsId", EmpPoints.seItem.id);
            ajax.start();
        };
        Feng.confirm("是否删除选中的"+EmpPoints.seItem.empName +"的数据？ 删除不可恢复！", operation);
    }
};

/**
 * 查询员工积分列表
 */
EmpPoints.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    EmpPoints.table.refresh({query: queryData});
};

/**
 * 打开导入员工积分数据页面
 */
EmpPoints.import = function () {
    var index = layer.open({
        type: 2,
        title: '员工积分',
        area: [EmpPoints.width, EmpPoints.height], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/empPoints/empPoints_import'
    });
    this.layerIndex = index;
};


/**
 * 高级搜索
 */
EmpPoints.g_search = function () {

    //清参数
    EmpPoints.queryData = {};

    var index = layer.open({
        type: 2,
        skin: 'layui-layer-molv',
        title: '高级搜索',
        area: ['800px', '380px'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/empPoints/g_search',
        btn: ['确定','关闭'],
        yes: function(index, layero){
            var queryData = window["layui-layer-iframe" + index].EmpPoints.search2();

            EmpPoints.table.setQueryParams(queryData);
            EmpPoints.queryData = queryData;
            debugger
            EmpPoints.table.refresh();
            EmpPoints.table.empty();
            layer.close(index); //如果设定了yes回调，需进行手工关闭
        }
    });
    this.layerIndex = index;
};

EmpPoints.search2 = function () {

    var department = $("#department option:selected").val();
    var place = $("#place option:selected").val();
    var team = $("#team option:selected").val();
    var postType =$("#postType option:selected").val();

    var year = $("#year").val();
    var min = $("#min").val();
    var max = $("#max").val();

    if(min){EmpPoints.queryData.min = min}
    if(max){EmpPoints.queryData.max = max}
    if(department){
        EmpPoints.queryData.department = department;
    }
    if(place){
        EmpPoints.queryData.place = place;
    }
    if(team){
        EmpPoints.queryData.team = team;
    }
    if(postType){
        EmpPoints.queryData.postType = postType;
    }
    if(year){
        EmpPoints.queryData.year = year;
    }

    return EmpPoints.queryData;
};



$(function () {
    var defaultColunms = EmpPoints.initColumn();
    var table = new BSTable(EmpPoints.id, "/empPoints/list", defaultColunms);
    table.setPaginationType("client");
    EmpPoints.table = table.init();
});
